package com.hxc.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserLoginInterceptor extends HandlerInterceptorAdapter{
    //进入controller之前执行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断session中是否有key（值），有的话继续用户操作
       if(request.getSession().getAttribute("SESSION_USER") != null){
           return true;
       }
        //没有登录就进入登录页面
        response.sendRedirect(request.getContextPath()+"/user/check.html");
       return false;
    }
}
